<template>
  <div class="app-container main-box">
    <el-card class="border-none search-card" shadow="never">

       <el-form :model="queryParams" class="search-form" ref="queryRef" :inline="true" v-show="showSearch"
              label-width="85px" >

          <sh-search ref="search" :model="form" :resetBtn="true">
            
              <el-form-item label="施工许可" prop="licenceNum" >
                <el-input v-model="queryParams.licenceNum" placeholder="请输入施工许可编码" clearable
                  @keyup.enter.native="handleQuery" />
              </el-form-item>
              <el-form-item label="工程编码" prop="sectionCode" >
                <el-input v-model="queryParams.sectionCode" placeholder="请输入单位工程编码" clearable
                  @keyup.enter.native="handleQuery" />
              </el-form-item>
              <el-form-item label="工程类型" prop="sectionGenus" >
                <el-select v-model="queryParams.sectionGenus" placeholder="请选择单位工程类型(大类)" clearable>
                  <el-option v-for="dict in subject_genus" :key="dict.value" :label="dict.label" :value="dict.value" />
                </el-select>
              </el-form-item>
              <el-form-item label="所在省" prop="provinceCode" >
                <el-input v-model="queryParams.provinceCode" placeholder="请输入所在省代码" clearable
                  @keyup.enter.native="handleQuery" />
              </el-form-item>
              <el-form-item label="所在市" prop="cityCode" >
                <el-input v-model="queryParams.cityCode" placeholder="请输入所在市代码" clearable @keyup.enter.native="handleQuery" />
              </el-form-item>
              <el-form-item label="所在区" prop="areaCode" >
                <el-input v-model="queryParams.areaCode" placeholder="请输入所在区代码" clearable @keyup.enter.native="handleQuery" />
              </el-form-item>
              <el-form-item label="形象进度" prop="sectionXxjd" >
                <el-select v-model="queryParams.sectionXxjd" placeholder="请选择形象进度" clearable>
                  <el-option v-for="dict in section_xxjd" :key="dict.value" :label="dict.label" :value="dict.value" />
                </el-select>
              </el-form-item>
              <el-form-item label="工程状态" prop="sectionStatus" >
                <el-select v-model="queryParams.sectionStatus" placeholder="请选择工程状态" clearable>
                  <el-option v-for="dict in section_status" :key="dict.value" :label="dict.label" :value="dict.value" />
                </el-select>
              </el-form-item>
              <el-form-item label="所属监督站" prop="govunitName" >
                <el-select v-model="queryParams.govunitName" placeholder="请选择所属监督站名称" clearable>
                  <el-option v-for="dict in govunit_name" :key="dict.value" :label="dict.label" :value="dict.value" />
                </el-select>
              </el-form-item>

              <template v-slot:btn>
               <!-- <el-form-item class="bottom-btns"> -->
                <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
                <el-button icon="Refresh" @click="resetQuery">重置</el-button>
               <!-- </el-form-item> -->
             </template>
          </sh-search>

        </el-form>
    </el-card>

    <el-card class="border-none table-card" shadow="never">
      <el-row :gutter="10" class="mb8 action-btns">
        <el-col :span="1.5">
          <el-button type="primary" plain icon="Plus" @click="handleAdd"
            v-hasPermi="['sup:managerSection:add']">新增</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button type="success" plain icon="Edit" :disabled="single" @click="handleUpdate"
            v-hasPermi="['sup:managerSection:edit']">修改</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button type="danger" plain icon="Delete" :disabled="multiple" @click="handleDelete"
            v-hasPermi="['sup:managerSection:remove']">删除</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button type="warning" plain icon="Download" @click="handleExport"
            v-hasPermi="['sup:managerSection:export']">导出</el-button>
        </el-col>
        <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
      </el-row>

      <el-table v-loading="loading" border :data="managerSectionList" @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="单位工程ID" align="center" prop="id" />
        <el-table-column label="施工许可" align="center" prop="licenceNum" />
        <el-table-column label="工程编码" align="center" prop="sectionCode" />
        <el-table-column label="工程名称" align="center" prop="sectionName" />
        <el-table-column label="工程地址" align="center" prop="address" />
        <el-table-column label="工程类型" align="center" prop="sectionGenus">
          <template #default="scope">
            <dict-tag :options="subject_genus" :value="scope.row.sectionGenus" />
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template #default="scope">
            <el-button type="text" icon="Edit" @click="handleUpdate(scope.row)"
              v-hasPermi="['sup:managerSection:edit']">修改</el-button>
            <el-button type="text" icon="Delete" @click="handleDelete(scope.row)"
              v-hasPermi="['sup:managerSection:remove']">删除</el-button>
          </template>
        </el-table-column>
      </el-table>

      <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize"
        @pagination="getList" />
    </el-card>
    <!-- 添加或修改单位工程信息对话框 -->
    <el-dialog :title="title" v-model="open" width="1200px" append-to-body :fullscreen="dialogFullScreen"
      :class="[dialogFullScreen ? 'fullscreen' : 'no_fullscreen']">
      <template #title>
        <div class="custom_dialog_header">
          <span class="el-dialog__title">{{ title }}</span>
          <div class="custom_dialog_menu" @click="dialogFullScreen = !dialogFullScreen">
            <svg-icon class="fullscreen-icon" :icon-class="dialogFullScreen ? 'fullscreen-exit' : 'fullscreen'" />
          </div>
        </div>
      </template>
      <el-form ref="managerSectionRef" :model="form" :rules="rules" label-width="auto">
        <el-row>
          <el-col :span="24">
            <el-form-item label="项目代码" prop="subjectCode">
              <el-input v-model="form.subjectCode" placeholder="请输入项目代码" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="施工许可" prop="licenceNum">
              <el-input v-model="form.licenceNum" placeholder="请输入施工许可编码" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="工程编码" prop="sectionCode">
              <el-input v-model="form.sectionCode" placeholder="请输入单位工程编码" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="工程名称" prop="sectionName">
              <el-input v-model="form.sectionName" type="textarea" placeholder="请输入内容" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="工程地址" prop="address">
              <el-input v-model="form.address" type="textarea" placeholder="请输入内容" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="工程类型" prop="sectionGenus">
              <el-select v-model="form.sectionGenus" clearable filterable placeholder="请选择单位工程类型(大类)">
                <el-option v-for="dict in subject_genus" :key="dict.value" :label="dict.label"
                  :value="dict.value"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="所在省" prop="provinceCode">
              <el-input v-model="form.provinceCode" placeholder="请输入所在省代码" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="所在市" prop="cityCode">
              <el-input v-model="form.cityCode" placeholder="请输入所在市代码" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="所在区" prop="areaCode">
              <el-input v-model="form.areaCode" placeholder="请输入所在区代码" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="街道/镇" prop="townCode">
              <el-input v-model="form.townCode" placeholder="请输入街道/镇" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="工程造价/万元" prop="sectionCost">
              <el-input v-model="form.sectionCost" placeholder="请输入工程造价/万元" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="总面积(平方米)" prop="area">
              <el-input v-model="form.area" placeholder="请输入总面积(平方米)" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="X坐标" prop="gpsX">
              <el-input v-model="form.gpsX" placeholder="请输入X坐标" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="Y坐标" prop="gpsY">
              <el-input v-model="form.gpsY" placeholder="请输入Y坐标" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="建设规模" prop="sectionScale">
              <el-input v-model="form.sectionScale" type="textarea" placeholder="请输入内容" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="总长度(m)" prop="allLength">
              <el-input v-model="form.allLength" placeholder="请输入总长度(m)" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="开工日期(计划)" prop="planStartDate">
              <el-date-picker clearable v-model="form.planStartDate" type="date" value-format="yyyy-MM-dd"
                placeholder="选择开工日期(计划)">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="竣工日期(计划)" prop="planEndDate">
              <el-date-picker clearable v-model="form.planEndDate" type="date" value-format="yyyy-MM-dd"
                placeholder="选择竣工日期(计划)">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="形象进度" prop="sectionXxjd">
              <el-select v-model="form.sectionXxjd" clearable filterable placeholder="请选择形象进度">
                <el-option v-for="dict in section_xxjd" :key="dict.value" :label="dict.label"
                  :value="dict.value"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="工程状态" prop="sectionStatus">
              <el-select v-model="form.sectionStatus" clearable filterable placeholder="请选择工程状态">
                <el-option v-for="dict in section_status" :key="dict.value" :label="dict.label"
                  :value="dict.value"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="所属监督站" prop="govunitName">
              <el-select v-model="form.govunitName" clearable filterable placeholder="请选择所属监督站名称">
                <el-option v-for="dict in govunit_name" :key="dict.value" :label="dict.label"
                  :value="dict.value"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup name="ManagerSection">
import { listManagerSection, getManagerSection, delManagerSection, addManagerSection, updateManagerSection } from "@/api/sup/managerSection";
// import shSearch from '@/layout/components/Search';  main.js 已全局挂载








const { proxy } = getCurrentInstance();
const { subject_genus, section_xxjd, section_status, govunit_name } = proxy.useDict('subject_genus', 'section_xxjd', 'section_status', 'govunit_name');

const managerSectionList = ref([]);
const open = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
let router = useRouter();
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const title = ref("");
const dialogFullScreen = ref(false);
const daterangePlanStartDate = ref([]);
const daterangePlanEndDate = ref([]);
const daterangeCreateTime = ref([]);
const daterangeUpdateTime = ref([]);



const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    licenceNum: null,
    sectionCode: null,
    sectionName: null,
    address: null,
    sectionGenus: null,
    provinceCode: null,
    cityCode: null,
    areaCode: null,
    sectionXxjd: null,
    sectionStatus: null,
    govunitName: null
  },
  rules: {
    licenceNum: [
      { required: true, message: "施工许可编码不能为空", trigger: "blur" }
    ],
    sectionName: [
      { required: true, message: "单位工程名称不能为空", trigger: "blur" }
    ],
  }
});

const { queryParams, form, rules } = toRefs(data);

/** 查询单位工程信息列表 */
function getList() {
  loading.value = true;
  queryParams.value.params = {};
  if (null != daterangePlanStartDate && '' != daterangePlanStartDate) {
    queryParams.value.params["beginPlanStartDate"] = daterangePlanStartDate.value[0];
    queryParams.value.params["endPlanStartDate"] = daterangePlanStartDate.value[1];
  }
  if (null != daterangePlanEndDate && '' != daterangePlanEndDate) {
    queryParams.value.params["beginPlanEndDate"] = daterangePlanEndDate.value[0];
    queryParams.value.params["endPlanEndDate"] = daterangePlanEndDate.value[1];
  }
  if (null != daterangeCreateTime && '' != daterangeCreateTime) {
    queryParams.value.params["beginCreateTime"] = daterangeCreateTime.value[0];
    queryParams.value.params["endCreateTime"] = daterangeCreateTime.value[1];
  }
  if (null != daterangeUpdateTime && '' != daterangeUpdateTime) {
    queryParams.value.params["beginUpdateTime"] = daterangeUpdateTime.value[0];
    queryParams.value.params["endUpdateTime"] = daterangeUpdateTime.value[1];
  }
  listManagerSection(queryParams.value).then(response => {
    managerSectionList.value = response.rows;
    total.value = response.total;
    loading.value = false;
  });
}

// 取消按钮
function cancel() {
  open.value = false;
  reset();
}

// 表单重置
function reset() {
  form.value = {
    id: null,
    subjectCode: null,
    licenceNum: null,
    sectionCode: null,
    sectionName: null,
    address: null,
    sectionGenus: null,
    provinceCode: null,
    cityCode: null,
    areaCode: null,
    townCode: null,
    sectionCost: null,
    area: null,
    gpsX: null,
    gpsY: null,
    sectionScale: null,
    allLength: null,
    planStartDate: null,
    planEndDate: null,
    sectionXxjd: null,
    sectionStatus: null,
    createTime: null,
    updatorId: null,
    updatorName: null,
    updateTime: null,
    invalid: null,
    origin: null,
    govunitId: null,
    govunitName: null
  };
  proxy.resetForm("managerSectionRef");
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  reset();
  daterangePlanStartDate.value = [];
  daterangePlanEndDate.value = [];
  daterangeCreateTime.value = [];
  daterangeUpdateTime.value = [];
  proxy.resetForm("queryRef");
  handleQuery();
}

// 多选框选中数据
function handleSelectionChange(selection) {
  ids.value = selection.map(item => item.id);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
}

/** 新增按钮操作 */
function handleAdd() {
  reset();
  open.value = true;
  title.value = "添加单位工程信息";

}

/** 修改按钮操作 */
function handleUpdate(row) {
  reset();
  const id = row.id || ids.value
  getManagerSection(id).then(response => {
    form.value = response.data;

    open.value = true;
    title.value = "修改单位工程信息";
  });
}

/** 提交按钮 */
function submitForm() {
  proxy.$refs["managerSectionRef"].validate(valid => {
    if (valid) {
      if (form.value.id != null) {
        updateManagerSection(form.value).then(response => {
          proxy.$modal.msgSuccess("修改成功");
          open.value = false;
          getList();
        });
      } else {
        addManagerSection(form.value).then(response => {
          proxy.$modal.msgSuccess("新增成功");
          open.value = false;
          getList();
        });
      }
    }
  });
}

/** 删除按钮操作 */
function handleDelete(row) {
  const ids = row.id || ids.value;
  proxy.$modal.confirm('是否确认删除单位工程信息编号为"' + ids + '"的数据项？').then(function () {
    return delManagerSection(ids);
  }).then(() => {
    getList();
    proxy.$modal.msgSuccess("删除成功");
  }).catch(() => { });
}

/** 导出按钮操作 */
function handleExport() {
  proxy.download('sup/managerSection/export', {
    ...queryParams.value
  }, `managerSection_${new Date().getTime()}.xlsx`)
}



onActivated(() => {
  getList();

})

getList();

</script>

<style lang='scss' scoped>
.search-form{
  .sh-search .el-form-item .el-input {
     width: 210px;
    }
    .sh-search .el-form-item .el-select{
      width: 210px;
      }

      // .sh-search {
      //   .el-form-item{
      //     :deep(.el-form-item__label) {
      //       color: blue;
      //       text-align-last: justify;
      //       display: inline;
            
      //      }
      //     }
      // }

      
} 
</style>
